package fu.capstone.hanoicityguide.presentation.activity;

import org.mapsforge.map.android.graphics.AndroidGraphicFactory;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import fu.capstone.hanoicityguide.R;
import fu.capstone.hanoicityguide.common.billing.utils.IabHelper;
import fu.capstone.hanoicityguide.dataaccess.webservice.WebServiceDAOImpl;

public class SplashActivity extends Activity {

	private IabHelper mHelper;

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (mHelper != null)
			mHelper.dispose();
		mHelper = null;
	}

	public static boolean checkUpdate;
	private TextView txtStatus;
	private WebServiceDAOImpl dao;
	private AlertDialog.Builder alertDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);

		AndroidGraphicFactory.createInstance(this.getApplication());
		txtStatus = (TextView) findViewById(R.id.txtStatus);

		checkUpdate = false;
		dao = new WebServiceDAOImpl(this, txtStatus);
		checkForUpdate();

	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		txtStatus = (TextView) findViewById(R.id.txtStatus);
		dao = new WebServiceDAOImpl(this, txtStatus);
		dao.execute();
	}

	public void checkForUpdate() {
		// call thread update
		try {
			dao.execute();
		} catch (Exception e) {
			Log.v("SplashActivity : ", e.toString());
		}
	}

	public void setStatus(String status) {
		txtStatus.setText(status);
	}

}
